﻿using System;
using System.Linq;

using Bootstrap5.Abstractions;

using Microsoft.AspNetCore.Components;

namespace Bootstrap5;

/// <summary>
/// Represents a flexible and extensible content container.
/// </summary>
[CssClass("card")]
public class Card:BootstrapChildContentWithCascadingValueComponentBase<Card>
{
    [Parameter][CssClass("bg-")] public BgColor? BgColor { get; set; }
    [Parameter] [CssClass("border-")] public Color? BorderColor { get; set; }

    protected override void CreateCssClass(ICssClassBuilder builder)
    {
        if (BgColor.HasValue)
        {
            if (new [] { Bootstrap5.BgColor.Warning, Bootstrap5.BgColor.Info, Bootstrap5.BgColor.Light }.Contains(BgColor.Value))
            {
                builder.Add("text-dark");
            }
            else
            {
                builder.Add("text-white");
            }
        }
    }
}

/// <summary>
/// Render cards as a single, attached element with equal width and height columns.
/// </summary>
[CssClass("card-group")]
public class CardGroup : BootstrapChildContentComponentBase
{

}

public abstract class CardChildComponentBase<TChildComponent> : BootstrapChildContentWithChildCascadingComponentBase<TChildComponent,Card>
    where TChildComponent : BootstrapComponentBase
{
    protected CardChildComponentBase() { }

    [Parameter] [CssClass("text-")]public TextColor? TextColor { get; set; }
    [Parameter] public virtual string TagName { get; set; } = "div";

    protected override string GetHtmlTagName() => TagName;
}

/// <summary>
/// Represents a title section in <see cref="Card"/> component.
/// </summary>
public class CardTitle : CardChildComponentBase<CardTitle>
{
    /// <summary>
    /// <c>true</c> to set the title to be subtitle, otherwise for main title set <c>false</c>.
    /// </summary>
    [Parameter] public bool Subtitle { get; set; }

    protected override void CreateCssClass(ICssClassBuilder builder)
    {
        builder.Add("card-title",!Subtitle).Add("card-subtitle",Subtitle);
    }
}

/// <summary>
/// 
/// </summary>
[CssClass("card-text")]
public class CardText : CardChildComponentBase<CardText>
{
    [Parameter]public override string TagName { get; set; } = "p";
}

/// <summary>
/// 
/// </summary>
[CssClass("card-link")]
public class CardLink : CardChildComponentBase<CardLink>
{
    [Parameter] public override string TagName { get; set; } = "a";
}

/// <summary>
/// Represents an &lt;img> element in <see cref="Card"/> component.
/// </summary>
[HtmlTag("img")]
public class CardImage : BootstrapChildContentWithChildCascadingComponentBase<CardImage, Card>
{
    [Parameter] [CssClass("card-img-")] public UpDownPlacement? Placement { get; set; }
}

[CssClass("card-body")]
public class CardBody : CardChildComponentBase<CardBody>
{

}
[CssClass("card-header")]
public class CardHeader : CardChildComponentBase<CardHeader>
{

}

[CssClass("card-footer")]
public class CardFooter : CardChildComponentBase<CardFooter>
{

}

[CssClass("card-img-overlay")]
public class CardImageOverlay : CardChildComponentBase<CardImageOverlay>
{

}